/*
	protected: 	专门为继承（子类）设计的;
		用public继承，那么基类所有的访问标识在子类不变，
	   即protected还是protected， 次方式与private的public继承相同。
	   	protected只有类本省和类的子类可以访问，对象（类外）无法访问。
	
	private:
		private只有基类可以访问，子类也不能访问(不可见).

*/

#include <iostream>

using namespace std;

class figure{
	protected:
		double x, y;

	public:
		void set_dim(double i, double j=0) {
			x = i;
			y = j;
		}

		virtual void show_area() {
			cout << "No area computation defined";
			cout << "for this class.\n";
		}
};

class triangle : public figure {
	public:
		void show_area() {
			cout << "Triangle with high ";
			cout << x << " and base " << y;
			cout << " has a area of ";
			cout << x * 0.5 * y << "\n";
		}
};

class square : public figure {
	public:
		virtual void show_area() {
			cout << "Square with dimension ";
			cout << x << " * " << y;
			cout << " has an area of ";
			cout << x * y << "\n";
		}
};

class circle : public figure {
	public:
		virtual void show_area () {
			cout << "Circle with radius ";
			cout << x;
			cout << " has an area of ";
			cout << 3.14 * x * x << "\n";
		}
};

int main(int argc, char * argv[]) {
	figure * p;
	triangle t;
	square s;
	circle c;

	p = &t;
	p->set_dim(10.0, 5.0);
	p->show_area();

	p = &s;
	p->set_dim(10.0, 5.0);
	p->show_area();

	p = &c;
	p->set_dim(9.0);
	p->show_area();

	return 0;
}
